package com.csi.jf.crucible.ptservice.service.impl;

import java.util.List;

import com.chinasofti.ro.bizframework.core.orm.IDAO;
import com.chinasofti.ro.bizframework.core.orm.Page;
import com.chinasofti.ro.bizframework.core.orm.entity.Model;
import com.csi.jf.crucible.ptservice.model.CodePackages;
import com.csi.jf.crucible.ptservice.model.ProjectTemp;
import com.csi.jf.crucible.ptservice.service.CodePackagesService;

/**
 * <p>Service Impl</p>
 * 
 * @author BizFoundation
 * @version 1.0
 * @since 1.0
 */
public class CodePackagesServiceImpl implements CodePackagesService {

	private IDAO dao;
	
	public void setDao(IDAO dao) {
		this.dao = dao;
	}

	/**
	 * 根据id查询数据
	 * 
	 * @param id
	 * @return model
	 */
	public Model findById(Long id) {
		CodePackages codePackages = new CodePackages();
		codePackages.setId(id);
		return (Model) dao.createQuery(codePackages).first();
	}
	
	/**
	 * 分页查询
	 * 
	 * @param codePackages
	 * @param page 分页
	 * @return
	 */
	public Page findByPage(CodePackages codePackages, Page page) {
		String sql = codePackages.getSql("list", dao.dbMeta());//使用codePackages.hbm.xml中的id为list的sql查询
		return dao.createNamedQuery(codePackages.getClass(),sql, codePackages).fetch(page);
	}
	
	/**
	 * 批量删除数据
	 * 
	 * @param ids
	 * @return int[] delete records
	 */
	public int[] batchDelete(String ids) {
		CodePackages codePackages = new CodePackages();
		return dao.batchDelete(codePackages, ids);
	}

	/**
	 * 保存数据
	 * @param Model
	 */
	public void save(Model model) {
		dao.save(model);
	}

	/**
	 * 更新数据
	 * @param Model
	 */
	public void update(Model model) {
		dao.update(model);
	}
	
	/**
	 * 获取项目信息  临时用
	 * @author JCJ
	 */
	public List<ProjectTemp> getProjectInfo(String manager) {
		ProjectTemp jfProjectTemp=new ProjectTemp();
		StringBuffer sql=new StringBuffer();
		sql.append("select projectId,projectName from jf_pts_project where manager="+manager);
		@SuppressWarnings("unchecked")
		List<ProjectTemp> projectList = dao.createNamedQuery(ProjectTemp.class, sql.toString(), jfProjectTemp).list();
		return projectList;
	}

	@Override
	public ProjectTemp getProjectInfoByID(Long proID) {
		ProjectTemp jfProjectTemp=new ProjectTemp();
		jfProjectTemp.setProjectId(proID);
		return (ProjectTemp)dao.createQuery(jfProjectTemp).first();
	}
	
	
}